.PHONY: help install install-dev test test-cov lint format clean build upload

# 默认目标
help:
	@echo "可用的命令:"
	@echo "  install      - 安装包"
	@echo "  install-dev  - 安装开发依赖"
	@echo "  test         - 运行测试"
	@echo "  test-cov     - 运行测试并生成覆盖率报告"
	@echo "  lint         - 运行代码检查"
	@echo "  format       - 格式化代码"
	@echo "  clean        - 清理构建文件"
	@echo "  build        - 构建包"
	@echo "  upload       - 上传到PyPI"

# 安装包
install:
	pip install -e .

# 安装开发依赖
install-dev:
	pip install -e ".[dev]"

# 运行测试
test:
	pytest

# 运行测试并生成覆盖率报告
test-cov:
	pytest --cov=toolbelt --cov-report=html --cov-report=term

# 代码检查
lint:
	flake8 toolbelt tests
	mypy toolbelt

# 格式化代码
format:
	black toolbelt tests

# 清理构建文件
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info/
	rm -rf .pytest_cache/
	rm -rf .coverage
	rm -rf htmlcov/
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete

# 构建包
build: clean
	python -m build

# 上传到PyPI (需要先配置twine)
upload: build
	twine upload dist/*

# 检查包
check:
	twine check dist/*

# 测试下载工具
test-download:
	@echo "测试下载工具..."
	python -m toolbelt.downloader -i https://httpbin.org/json -o test_download.json
	@echo "下载测试完成，检查 test_download.json 文件"

clean-test:
	rm -f test_download.json